import scala.collection.mutable.ArrayBuffer
import scala.util.control.Breaks

object prime {
  def main(args: Array[String]): Unit = {

    val n = 1000001
    val primeArrayBuffer = ArrayBuffer[Int](2,3)
    val breakLoop = new Breaks
    breakLoop.breakable {
      for (i <- 2 to n) {
        val flage = isPrime(i)
        if (flage) {
          primeArrayBuffer += i
        }
        if (primeArrayBuffer.size > 10000) {
          println(primeArrayBuffer.last)
          breakLoop.break()
        }
      }
    }

  }

  def isPrime(p:Int):Boolean = {
    if (p % 6 == 1 || p % 6 == 5) {
      for (i <- 5.to(math.sqrt(p).toInt, 6)) {
        if (p % i == 0 || p % (i + 2) == 0)
          return false
      }
    }else {
      return false
    }
    true
  }
}
